<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-date-picker @change="changeWarrantyMoth" v-model="warrantyMoth" format="YYYY-MM" value-format="YYYY-MM" type="month" placeholder="请选择维保到期日期"/>
				<el-switch @change="changeOld" v-model="isContainOldMaintenance" inline-prompt active-text="包含以往过期资产" inactive-text="不包含以往过期资产"
				/>
				<fsButton ref="button" plain size="default" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
			</div>
			<div class="right-panel">
				<ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="code" placeholder="请输入资产编码" :fixed-param="fixedParams" :init-params="searchParams"></ex-search>
			</div>
		</el-header>
		<el-main class="nopadding">
			<ex-table id="checkTaskTable" ref="table" :auto-refresh="false" :tablename="'维保到期查询'" :columns="columns" :url="this.$API.asset.asset.list.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
		</el-main>
	</el-container>
	<data-card ref="dataCard"></data-card>
</template>

<script>
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import ExTreeNavigation from "@/components/exSearchTree/index.vue";
import ExSearchTree from "@/components/exSearchTree/index.vue";
import scSelectFilter from "@/components/scSelectFilter/index.vue";
import tool from "@/utils/tool";
import DataCard from "@/views/asset/card/card.vue";
import moment from "moment";
import globalparam from "@/constant/model/globalparam";
import BaseTemplate from "@/utils/baseTemplate";
import useTabs from "@/utils/useTabs";
import router from "@/router";
export default {
	name: '维保到期查询',
	components: {
		DataCard,
		scSelectFilter,
		ExSearchTree,
		ExTreeNavigation,
		ExSearch,
		ExTable,
	},
	data() {
		return {
			dialog: {
				save: false,
				permission: false,
			},
			apiObj: [],
			buttons: [
				{name: "导出", icon: "el-icon-download", click: "export", type: "info", permission: "export"},
			],
			searches: [
				{type: "daterange", name: "维保截止日期", code: "warrantyDateStart,warrantyDateEnd", placeholder: "请选择维保截止日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "input", name: "资产编码", code: "code", placeholder: "请输入资产编码", maxlength: 30, showLimit: true},
				{type: "input", name: "资产名称", code: "name", placeholder: "请输入资产名称"},
				{type: "daterange", name: "购置日期", code: "boughtDateStart,boughtDateEnd", placeholder: "请选择购置日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "tree-select", name: "资产分类", code: "assetCategoryIds", placeholder: "请选择资产分类", dictCode:'FamsAssetCategory',checkStrictly:true,multiple:true,dataPermissionProcess:true},
				{type: "input", name: "规格型号", code: "model", placeholder: "请输入规格型号"},
				{type: "tree-select", name: "使用部门", code: "usingDepartmentIds", placeholder: "请选择使用部门", dictCode:'SysOrganization',checkStrictly:true,multiple:true,dataPermissionProcess:true,permissionData:this.$TOOL.current.manageDeptIds()},
				{type: "selector", name: "使用人", code: "usingMenId", placeholder: "请选择使用人", dictCode:'SysUser'},
				{type: "input", name: "品牌", code: "brand", placeholder: "请输入品牌"},
				{type: "tree-select", name: "管理部门", code: "dutyDepartmentIds", placeholder: "请选择管理部门", dictCode:'SysOrganization',checkStrictly:true,multiple:true,dataPermissionProcess:true},
				{type: "select", name: "资产状态", code: "assetStatusIds", placeholder: "请选择资产状态", dictCode:'ASSET_STATUS',multiple:true},
				{type: "tree-select", name: "资产位置", code: "storePlaceIds", placeholder: "请选择资产位置", dictCode:'FamsPosition',checkStrictly:true,multiple:true},
			],
			columns: [
				{code: "assetStatusId", name: "资产状态", width:"65",formatter:"DICT",key: "ASSET_STATUS"},
				{code: "code", name: "资产编码", width:"135",click:"show1"},
				{code: "financialCode", name: "财务编码", width:"170"},
				{code: "name", name: "资产名称", width:"200"},
				{code: "other.warrantyDate", name: "维保截止日期", width:"110",formatter: "DATE"},
				{code: "boughtDate", name: "购置日期", width:"110",formatter: "DATE"},
				{code: "mainCategoryCode", name: "资产大类",width:"110", formatter:"DICT",key: "FamsAssetCategory"},
				{code: "assetCategoryId", name: "资产小类",width:"180", formatter:"DICT",key: "FamsAssetCategory"},
				{code: "storePlaceId", name: "资产位置",width: "120", formatter:"DICT",key: "FamsPosition"},
				{code: "workingLife", name: "使用月份", width:"150"},
				{code: "brand", name: "品牌", width:""},
				{code: "model", name: "规格型号", width:""},
				{code: "serialCode", name: "资产序列号", width:"150"},
				{code: "assetCount", name: "数量", width:"50",summary:true},
				{code: "originalValue", name: "资产原值", width:"100",summary:true},
				{code: "netValue", name: "资产净值", width:"100",summary:true},
				{code: "usingMenId", name: "使用人", width:"110",formatter: "DICT",key: "SysUser"},
				{code: "usingDepartmentId", name: "使用部门", width:"150",formatter: "DICT",key: "SysOrganization"},
				{code: "dutyDepartmentId", name: "管理部门", width:"150",formatter: "DICT",key: "SysOrganization"},
				{code: "createTime", name: "入库日期", width:"110",formatter: "DATE"},
				{code: "other.scrapDate", name: "报废日期", width:"110",formatter: "DATE"},
				{code: "recipientOnDate", name: "领用日期", width:"110",formatter: "DATE"},
			],
			parentLevelCode:"",
			assetIds:[],
			loading: false,
			warrantyMoth: moment(new Date()).format("YYYY-MM"),
			isContainOldMaintenance: false,
			assetStatisticsRange: '',
			deptIds:this.$TOOL.current.manageDeptIds(),
			assetCategoryIds: this.$TOOL.current.manageAssetCategoryIds(),
			fixedParams: {
				excludeStatus:['delete','scrap'],
				deptIds:this.$TOOL.current.manageDeptIds(),
				assetCategoryIds: this.$TOOL.current.manageAssetCategoryIds(),
			},
			searchParams:{},
			loginUsers: tool.current.user(),
		}
	},
	created() {
		//如果是通过跳转过来的，标签的名称设置为跳转后的标题
		let route = router.currentRoute.value;
		if(route.meta){
			this.title=route.meta.title;
		}
		let routeParams = this.$store.state.routeParams[this.$route.params.key];
		if(routeParams){
			if(routeParams.title){
				useTabs.setTitle(routeParams.title);
				document.title = routeParams.title;
			}
			this.buttons = [
				{name: "导出", icon: "el-icon-download", click: "export", type: "info"},
			]
			if (routeParams.fixedParams) {
				Object.assign(this.fixedParams,routeParams.fixedParams);
				if(routeParams.fixedParams.assetStatisticsRange){
					this.assetStatisticsRange = routeParams.fixedParams.assetStatisticsRange;
				}
				if (routeParams.fixedParams.isContainOldMaintenance){
					this.isContainOldMaintenance = routeParams.fixedParams.isContainOldMaintenance;
				}
				if (routeParams.fixedParams.deptIds){
					this.deptIds = routeParams.fixedParams.deptIds;
				}
			}
			if (routeParams.searchParams) {
				Object.assign(this.searchParams,routeParams.searchParams);
			}
		}
	},
	async mounted() {
		if(!this.fixedParams.assetStatisticsRange){
			this.assetStatisticsRange = await this.$cache.data.loadGlobalParam(globalparam.assetStatisticsRange.paramCode);
			this.fixedParams.assetStatisticsRange = this.assetStatisticsRange;
		}
		await this.searchHandler();
	},
	beforeMount() {

	},
	methods: {
		buttonHandler(index, name) {
			this.$options.methods[name](this, index);
		},
		// async searchTreeHandler(data) {
		// 	let queryParams = {pathCode:data.levelCode}
		// 	this.parentLevelCode= data.levelCode;
		// 	await this.$refs.table.refresh(queryParams);
		// },

		async searchHandler() {
			let queryParams = {pathCode: this.parentLevelCode}
			queryParams.isContainOldMaintenance = this.isContainOldMaintenance;
			queryParams.warrantyMoth = this.warrantyMoth;
			console.log(queryParams);
			await this.$refs.table.refresh(queryParams);
		},
		columnClickHandler(name,data){
			this.$options.methods[name](this, data);
		},
		changeOld(val){
			this.isContainOldMaintenance = val;
			this.searchHandler()
		},
		changeWarrantyMoth(val){
			this.warrantyMoth = val;
			this.searchHandler()
		},
		//查看
		async show1(_this, row) {
			let assetCategory = await _this.$cache.data.loadAssetCategory(row.assetCategoryId);
			try {
				_this.loading = true;
				let entity = {cardId: assetCategory.assetCardId, _editFlag: false}
				_this.$nextTick(() => {
					_this.cardPreview = false;
					_this.$refs.dataCard.open(Object.assign(entity, row));
				});
			} finally {
				_this.loading = false;
			}
		},
		//导出
		async export(_this,index) {
      let attachParams = {};
      attachParams.isContainOldMaintenance = _this.isContainOldMaintenance;
      attachParams.warrantyMoth = _this.warrantyMoth;
      attachParams.exportType = "maintenanceAsset";
      let exportApi = _this.$API.asset.asset.export;
      let exTableRef = _this.$refs.table;
      let exportBtnRef = _this.$refs.button;
      let exportBtnIndex = index;
      await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, exportBtnIndex, exTableRef);
		},
	}
}

</script>
<style scoped>

</style>
